package com.itheima.googleplay9.manager;

import com.itheima.googleplay9.bean.AppInfo;

import java.io.File;

/**
 * 用来封装下载任务相关的数据信息，如已经下载的长度，总大小，下载文件保存的路径
 * ，下载状态等
 * Created by lxj on 2016/5/28.
 */
public class DownloadInfo {
    private long id;//下载任务的唯一标识，可以是其他的如packageName
    private String downloadUrl;//下载的地址
    private long currentLength;//已经下载的长度
    private long size;//总大小
    private int state;//下载状态

    private String path;//下载文件的保存路径

    /**
     * 初始化DownloadInfo对象
     * @return
     */
    public static DownloadInfo create(AppInfo appInfo){
        DownloadInfo downloadInfo = new DownloadInfo();
        downloadInfo.setId(appInfo.getId());
        downloadInfo.setDownloadUrl(appInfo.getDownloadUrl());
        downloadInfo.setSize(appInfo.getSize());
        //初始化state
        downloadInfo.setState(DownloadManager.STATE_NONE);
        downloadInfo.setCurrentLength(0);

        //设置下载文件的绝对路径：/mnt/sdcard/包名/download/有缘网.apk
        downloadInfo.setPath(DownloadManager.DOWNLOAD_DIR +
                File.separator + appInfo.getName()+".apk");

        return downloadInfo;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getDownloadUrl() {
        return downloadUrl;
    }

    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl;
    }

    public long getCurrentLength() {
        return currentLength;
    }

    public void setCurrentLength(long currentLength) {
        this.currentLength = currentLength;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}
